<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <!-- -----导入vue文件------ -->
        <script src="./lib/vue_2.5.22.js"></script>
        <script src="./lib/vue-router_3.0.2.js"></script>
    </head>
    <body>
        <div id="app">
            <!-- ----被vm实例控制的区域---- -->
            <router-link to = '/user'>User</router-link>
            <router-link to = '/register'>Register</router-link>
            <router-view></router-view>
        </div>
        <script>
            //创建路由组件
            const User = {
                template:`<div>
                    <h1>User</h1>
                    <router-link to = '/user/aa'>Tab1</router-link>
                    <router-view></router-view>    
                </div>
                `
            }
            const Register = {
                template:`<div>
                    <h1>Register</h1>
                    <router-link to = '/register/bb'>Tab2</router-link>
                    <router-view></router-view>    
                </div>
                `
            }
            const Tab1 = {
                template:`
                    <h1>我是Tab1</h1>
                `
            }
            const Tab2 = {
                template:`
                    <h1>我是Tab2</h1>
                `
            }
            //创建路由实例对象
            const router = new VueRouter({
                routes:[
                    {path:'/',redirect:'/register'},
                    {path:'/user',component:User,children:[
                        {path:'/user/aa',component:Tab1}
                    ]},
                    {path:'/register',component:Register,children:[
                        {path:'/register/bb',component:Tab2}
                    ]}
                ]
            })
            const vm = new Vue({
                el: '#app',
                data: {},
                //挂在实例对象
                router,
                methods: {}
            })
        </script>
    </body>
</html>